#include<iostream>
using namespace std;
const int N = 1e4 + 10;
typedef long long LL;
int s[N];
int n, x;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		s[i] = s[i - 1] + x;
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			if (s[j] - s[i - 1] == 0) {
				ans++;
			}
			else if (s[j] - s[i - 1] == j - i + 1) {
				continue;
			}
			else {
				ans += 2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}